/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import message.Message;
import java.util.Queue;
/**
 *
 * @author kinder
 */
public class QueueMonitor {

    private Queue<Message> messagesQueue;

    public QueueMonitor(Queue<Message> messagesQueue)
    {
        this.messagesQueue = messagesQueue;
    }

    public synchronized Message dequeue()
    {
        while(this.messagesQueue.isEmpty())
        {
            try{
                    wait();
            }
            catch (InterruptedException e){
                e.printStackTrace();
            }
        }

        return this.messagesQueue.poll();
    }

    public synchronized void enqueue(Message m)
    {
        this.messagesQueue.offer(m);
        notifyAll();
    }
}
